package com.zego.wawaji.third.push;

import com.zego.wawaji.base.module.ModuleMgr;
import com.noble.library.module.ModuleBase;
import com.zego.wawaji.wawaji_client.AppTinkerLike;

import java.util.HashSet;
import java.util.Set;

import cn.jpush.android.api.JPushInterface;

/**
 * 推送工具
 * Created by Su on 2017/12/29.
 */
public class PushMgr implements ModuleBase {
    private static String _FRONT = "front";
    private static String _BACK = "back";

    @Override
    public void init() {
        initPush();
    }

    @Override
    public void release() {
    }

    private void initPush() {
        initJPush();
    }

    /**
     * 极光推送
     */
    private void initJPush() {
        JPushInterface.setDebugMode(false);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(AppTinkerLike.getContext());            // 初始化 JPush
    }

    /**
     * 以用户id做tag设置给JPush
     * <p>
     * alis: string     tag : set集合
     * <p>
     * uid: alias     前后台： tag
     */
    public void setJPushTag(long uid) {
        Set<String> set = new HashSet<>();
        set.add(_FRONT);//名字任意，可多添加几个
        JPushInterface.setAliasAndTags(AppTinkerLike.getContext(), String.valueOf(uid), set, null);
    }

    /**
     * 更新tag
     */
    public void resetJPushTag(boolean isFront) {
        long uid = ModuleMgr.getCenterMgr().getMyInfo().getUid();
        String tag = isFront ? _FRONT : _BACK;
        Set<String> set = new HashSet<>();
        set.add(tag);//名字任意，可多添加几个
        JPushInterface.setAliasAndTags(AppTinkerLike.getContext(), String.valueOf(uid), set, null);
    }
}
